<template>
  <div>
    <h1 align="center">会员添加页面</h1>
    <table class="table table-border">
      <tr>
        <td align="center">会员名称</td>
        <td>
          <input type="text" v-model="state.m_user" />
        </td>
      </tr>
      <tr>
        <td align="center">出生日期</td>
        <td>
          <input type="date" v-model="state.m_date" />
        </td>
      </tr>
      <tr>
        <td align="center">办理日期</td>
        <td>
          <input type="date" v-model="state.m_Pdate" />
        </td>
      </tr>
      <tr>
        <td align="center">性别</td>
        <td>
          <input type="text" v-model="state.m_sex" />
        </td>
      </tr>
      <tr>
        <td align="center">积分余额</td>
        <td>
          <input type="text" v-model="state.m_menony" />
        </td>
      </tr>
      <tr>
        <td align="center">姓名</td>
        <td>
          <input type="text" v-model="state.m_name" />
        </td>
      </tr>
      <tr>
        <td align="center">头像</td>
        <td>
          <img
            src="https://img0.baidu.com/it/u=209473111,1749122512&fm=253&fmt=auto&app=138&f=PNG?w=236&h=236"
            alt=""
            width="50"
            height="50"
          />
        </td>
      </tr>
      <tr>
        <td align="center">状态</td>
        <td>
          <input type="radio" name="IsDelte" value="1" />正常
          <input type="radio" name="IsDelte" value="0" />禁用
        </td>
      </tr>
      <tr>
        <td colspan="2" align="center">
          <input
            type="button"
            value="添加"
            @click="Funbao"
            class="btn btn-primary"
          />
        </td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { reactive, toRefs, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { useRoute } from 'vue-router';
const router = useRouter();
const route = useRoute();
let data: any = reactive({
  state: {
    m_user: '',
    m_date: '',
    m_Pdate: '',
    m_sex: '',
    m_menony: '',
    m_name: ''
  }
});
let { state } = toRefs(data);

const Funbao = () => {
  let obj = {
    mid: 0,
    m_user: state.value.m_user,
    m_date: state.value.m_date,
    m_ptoper:
      'https://img0.baidu.com/it/u=209473111,1749122512&fm=253&fmt=auto&app=138&f=PNG?w=236&h=236',
    m_Pdate: state.value.m_Pdate,
    m_sex: state.value.m_sex,
    m_menony: state.value.m_menony,
    m_name: state.value.m_name
  };
  if (state.value.m_user == '') {
    alert('会员不能为空');
    return;
  }
  if (state.value.m_date == '') {
    alert('出生日期不能为空');
    return;
  }
  if (state.value.m_Pdate == '') {
    alert('办理日期不能为空');
    return;
  }
  if (state.value.m_sex == '') {
    alert('性别不能为空');
    return;
  }
  if (state.value.m_menony == '') {
    alert('剩余积分不能为空');
    return;
  }
  if (state.value.m_name == '') {
    alert('姓名不能为空');
    return;
  }
  axios({
    url: '/api/Meber/Add',
    method: 'post',
    data: obj
  })
    .then((res) => {
      console.log(res);
      if (res.data.data == 1) {
        alert('添加成功');
        router.push('/about');
      } else {
        alert('添加失败');
      }
    })
    .catch((err) => {
      console.log(err);
    });
};
</script>

<style scoped></style>
